{aide_template 'common/header'}
<link href="{$aideUrl}web/resource/css/util.min.css" rel="stylesheet">
<script type="text/javascript" src="{$aideUrl}web/resource/js/util.min.js?v=20170912"></script>
<ul class="nav nav-tabs">
	<li {if $op == 'display'} class="active" {/if}><a href="{php echo web_url('extend/type/display');}">视频分类管理</a></li>
	<li {if $op == 'post' && empty($cateId) && $_GPC['visible_level']!=1}class="active"{/if}><a href="{php echo web_url('extend/type/post');}">添加主分类</a></li>
	<!--<li {if $op == 'post' && empty($cateId) && $_GPC['visible_level']==1}class="active"{/if}><a href="{php echo web_url('extend/type/post',array('visible_level'=>1));}"><span style="color: red;">添加顶部分类</span></a></li>-->
	{if $op == 'post' && !empty($cateId)}
	<li class="active"><a href="{php echo web_url('extend/type/post');}">编辑视频分类</a></li>
	{/if}
</ul>
<div class="main">
{if $op == 'display'}
<style>
	td>i{cursor:pointer; display:inline-block; width:100%; height:100%; color:#428bca;}
	.category-caret{display:inline-block; width:20px; margin: 0 10px; text-align:center; cursor:pointer; color:#d9534f;}
	.add.add_level0{cursor:pointer;}
</style>
<form action="" method="post">
	<div class="panel panel-default">
		<div class="panel-heading clearfix">顺序号越大排列越靠前<span class="pull-right"><a href="javascript:;" class="js-category-all">全部折叠 </a></span></div>
		<div class="panel-body table-responsive">
			<table class="table table-hover">
				<thead>
					<tr>
						<th style="width:auto">分类名称</th>
						<!--<th style="width:60px; text-align:center;">类别</th>-->
						<th style="width:180px; text-align:right">操作</th>
					</tr>
				</thead>
				<tbody>
					{loop $category $pcate}
					<tr>
						<td class="text-left">
							<input type="text" class="form-control" maxlength="50" style='display:inline;width:450px;' name="name[{$pcate['id']}]" value="{$pcate['name']}" />
							{if empty($pcate['redirect'])}
                                <a href="{php echo web_url('extend/type/post', array('fatherid' => $pcate['id']))}" class="add add_level1" title="添加子分类" data-pid="{$pcate['id']}" data-name="{$pcate['name']}">
                                    <i class="fa fa-plus-circle"></i>添加子类
									<i class="fa"></i>{if $pcate['parentid']==0}{else}上级分类：{$arr[$pcate['parentid']]['name']}{/if}
								</a>
                                {if !empty($category[$pcate['id']])}
                                <span class="category-caret">
                                    <i class="fa fa-caret-up js-category-up" style="display:none;" pid="{$pcate['id']}"></i>
                                </span>
                                {/if}
                            {/if}
						</td>
						<td class="text-right" style="position:relative;">
							<a href="{php echo web_url('extend/type/post', array('id' => $pcate['id']));}" title="编辑">编辑</a> -
							<a href="javascript:;" cate-id="{$pcate['id']}" parentid="{$pcate['parentid']}" title="删除" class="js-delete">删除</a>
						</td>
					</tr>
					{/loop}

				</tbody>
			</table>
		</div>
	</div>
	<div class="form-group col-md-12">
		<input name="submit" type="submit" class="btn btn-primary min-width" value="保存">
		<input type="hidden" name="token" value="{$_W['token']}" />
	</div>
</form>
<script type="text/javascript">
{if IMS_VERSION=='0.8'}
require(['jquery', 'util'], function($, util){
	$('.js-copy').each(function(){
		var id=$(this).attr('data-id');
		util.clip($("#js-copy"+id), $(this).attr('data-url'));
	});
});
{/if}
//微擎0.8显示switch
require(['bootstrap.switch'],function($){
	// 启用状态
	$('.js-flag:checkbox').bootstrapSwitch({onText: '启用', offText: '禁用'});
	$('.js-flag:checkbox').on('switchChange.bootstrapSwitch', function(event, state) {
		var id = $(this).data('id');
		var status = state ? 1 : 0;
		$.post("{php echo web_url('extend/type/status')}", {id : id, status : status}, function (data){
				util.tips(data.message);
		}, 'json');
	});

});
//微擎1.0+显示switch
$('.switch').click(function(e){
	var id = $(this).data('id');
	var state = $(this).hasClass("switchOff");
	var status = state ? 1 : 0;
	$.getJSON("{php echo web_url('extend/type/status')}", {id : id, status : status}, function(data) {
		util.tips(data.message, 2000);
	});

	$(this).toggleClass("switchOff");
	$(this).toggleClass("switchOn");

});

$(function(){
	$('.js-clip').each(function(){
		util.clip(this, $(this).data('url'));
	});
	$('.js-delete').click(function(e) {
		e.stopPropagation();
		var cateid = $(this).attr('cate-id');
		var parentid = $(this).attr('parentid');
		var $this = $(this);
		util.nailConfirm(this, function(state) {
			if (!state) return;
			$.post("{php echo web_url('extend/type/delete')}", {cateid : cateid, parentid : parentid}, function(data) {
				if(!data.errno){
					$this.parent().parent().remove();
				};
				util.tips(data.message);
			}, 'json');
		});
	});
	//添加父分类
	$('.add_level0').click(function(){
		var pid = $(this).attr('data-pid');
		var name = $(this).attr('data-name');
		var html = '<tr>' +
				'<td></td><td class="text-left"> <input type="text" class="form-control" maxlength="50" style="display:inline;width:90%;" name="add_parent_name[]" value="" placeholder="分类名称" /></td><td></td>'+
				'<td class="text-center"> <input type="text" class="form-control" maxlength="2" name="add_parent_displayorder[]" value="0" placeholder="分类排序"/></td>' +
				'<td colspan="1"><i class="fa fa-times-circle" onclick="$(this).parents(\'tr\').remove()"></i></td>' +
				'</tr>';
		$(this).parents('tr').before(html)
	});
	//控制显示
	$('.js-category-all').click(function() {
		if($(this).hasClass('js-collapse')) {
			$('.js-child-category').fadeOut("slow");
			$('.fa-caret-up').hide();
			$('.fa-caret-down').show();
			$(this).text('全部展开').removeClass('js-collapse');

		} else {
			$('.js-child-category').fadeIn("slow");
			$('.fa-caret-up').show();
			$('.fa-caret-down').hide();
			$(this).text('全部折叠').addClass('js-collapse');
		}
	});

	$('.js-category-up').click(function() {
		var parentId = $(this).attr('pid');
		console.log(parentId);
		$('tr[pid="'+parentId+'"]').fadeOut("slow");
		$(this).prev().show();
		$(this).hide();
	});
	$('.js-category-down').click(function() {
		var parentId = $(this).attr('pid');
		console.log(parentId);
		$('tr[pid="'+parentId+'"]').fadeIn("slow");
		$(this).next().show();
		$(this).hide();
	});
	function addChild(parentId) {

    }
});
</script>

{elseif $op == 'post'}

<div class="clearfix">
	<form action="" method="post" class="form-horizontal form" enctype="multipart/form-data" id="form1">
		<div class="panel panel-default" id="step1">
			<div class="panel-heading">
				分类管理
			</div>
			<div class="panel-body">
				{if !empty($parent)}
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">上级分类:</label>
					<div class="col-sm-9 col-xs-12 control-label" style="text-align:center;">{$parent['name']}</div>
				</div>
				{/if}
				<div class="form-group">
					<label class="col-md-2 control-label"><span style="color:red;">*</span> 分类名称：</label>
					<div class="col-md-9">
						<input class="form-control" type="text" maxlength="255" name="name" value="{$category['name']}" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">视频</label>
					<div class="col-sm-9 col-xs-12">
						<input type="hidden" name="file_path"   value="{$category['file_path']}">
						{php echo tpl_form_field_video('file_path', $category['file_path']);}
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-2 control-label"></label>
					<div class="col-md-9">
						<input name="submit" id="submit" type="submit" value="保存" class="btn btn-primary min-width">
						<input type="hidden" name="token" value="{$_W['token']}" />
					</div>
				</div>
			</div>
		</div>
	</form>
</div>
{/if}
</div>

{aide_template 'common/footer'}
